﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;


namespace heyirunde.wx
{
    /// <summary>
    /// caidan 的摘要说明
    /// </summary>
    public class caidan : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";


         


            RestClient client = new RestClient("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + wxconfig.getToken());
            RestRequest request = new RestRequest(Method.POST);




            JObject o = new JObject();
            JArray array = new JArray();

            JObject o1 = new JObject();
            o1["name"] = "和易公会";
            o1["type"] = "view";
            o1["url"] = "http://heyirunde.com";
            array.Add(o1);


            JObject o2 = new JObject();
            o2["name"] = "润德书院";
            JArray array2 = new JArray();
            JObject o21 = new JObject();
            o21["name"] = "招募合伙人";
            o21["type"] = "click";
            o21["key"] = "haibao_hehuo";
            array2.Add(o21);

            JObject o22 = new JObject();
            o22["name"] = "正在直播";
            o22["type"] = "view";
            o21["url"] = "https://www.gcard.com/ucard/detail?id=8c548147-a78d-421b-8f61-c2166f6b9eaa&userid=76c146a6-9653-44a8-b9c7-a13be3ec19cf";
            array2.Add(o22);
            o2["sub_button"] = array2;

            array.Add(o2);

            JObject o3 = new JObject();
            o3["name"] = "会员中心";
            JArray array3 = new JArray();
            JObject o31 = new JObject();
            o31["name"] = "我要推广";
            o31["type"] = "click";
            o31["key"] = "haibao_tuiguang";
            array3.Add(o31);
            JObject o32 = new JObject();
            o32["name"] = "我要签到";
            o32["type"] = "view";
            o32["url"] = "https://w.url.cn/s/A4GW0Xb";
            array3.Add(o32);
            JObject o33 = new JObject();
            o33["name"] = "服务咨询";
            o33["type"] = "view";
            o33["url"] = "http://heyirunde.com/wx/service.html";
            array3.Add(o33);

            array.Add(o3);



            o3["sub_button"] = array3;





            o["button"] = array;



         
         
            

            request.AddJsonBody(o);

            /*
                        request.AddJsonBody(
                               new 
                               {
                                   button = new[]
                           {
                              new{
                               name = "和易集团",

                               sub_button = new []
                               {
                                 new {
                                       type="view",
                                       name="和易集团",
                                       url="http://heyirunde.com/"
                                    },
                                 new {
                                       type="view",
                                       name="挂牌上市",
                                       url="http://www.heyirunde.com/appear.html"
                                    },
                                 new {
                                       type="view",
                                       name="政策顾问",
                                       url="http://heyirunde.com/ministry.html"
                                    },new {
                                       type="view",
                                       name="财务顾问",
                                       url="http://heyirunde.com/finance.html"
                                    },new {
                                       type="click",
                                       name="和易众创",
                                       url="http://heyirunde.com/crowd.html"
                                    }
                               }

                              },
                              new
                              {
                             name = "润德书院",
                              sub_button = new []
                               {
                                 new {
                                       type="view",
                                       name="书院简介",
                                       url="http://heyirunde.com/academy.html"
                                    },
                                 new {
                                       type="view",
                                       name="政策解读",
                                       url="http://heyirunde.com/"
                                    },
                                 new {
                                       type="view",
                                       name="正在直播",
                                       url="https://www.gcard.com/ucard/detail?id=8c548147-a78d-421b-8f61-c2166f6b9eaa&userid=76c146a6-9653-44a8-b9c7-a13be3ec19cf"
                                    }
                               }
                              },
                               new
                              {
                             name = "会员中心",
                              sub_button = new []
                               {
                                 new {
                                       type="view",
                                       name="我要推广",
                                       url="http://heyirunde.com/wx/share.html"
                                    },
                                 new {
                                       type="view",
                                       name="签到",
                                       url="https://w.url.cn/s/A4GW0Xb"
                                    },
                                 new {
                                       type="view",
                                       name="学分商城",
                                       url="http://heyirunde.com/wx/shopping.html"
                                    },
                                 new {
                                       type="view",
                                       name="服务咨询",
                                       url="http://heyirunde.com/wx/service.html"
                                 }
                              }
                               }
                           }
                               });


                */



            /****************************
             * 
             * {
"button":[
{
"name":"和易公会",
"type":"view",
"url":"http://heyirunde.com"
},
{
"name":"润德书院",
"sub_button":[
{
"name":"招募合伙人",
"type":"click",
"key":"haibao_hehuo"

},
{
"name":"正在直播",
"type":"view",
"url":"https://www.gcard.com/ucard/detail?id=8c548147-a78d-421b-8f61-c2166f6b9eaa&userid=76c146a6-9653-44a8-b9c7-a13be3ec19cf"
}


]

},

{
"name":"会员中心",
"sub_button":[

{
"name":"我要推广",
"type":"click",
"key":"haibao_tui"

},

{
"name":"我要签到",
"type":"view",
"url":"https://w.url.cn/s/A4GW0Xb"

},
{
"name":"服务咨询",
"type":"view",
"url":"http://heyirunde.com/wx/service.html"

}


]

}



]


}
          ***/



            IRestResponse res = client.Execute(request);
            context.Response.Write(res.Content);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}